{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "56b0a4df-78cf-4cf1-bc8b-70bd933cbb36",
   "metadata": {},
   "source": [
    "> Agent in the terminal ~\n",
    "\n",
    "- 安装与升级\n",
    "\n",
    "```shell\n",
    "npm upgrade -g @google/gemini-cli\n",
    "```\n",
    "\n",
    "- `~/.gemini`\n",
    "    - `settings.json`：全局配置文件\n",
    "    - mcpServers 在这里配置\n",
    "- `.env`\n",
    "    - `GEMINI_API_KEY`\n",
    "    - `GEMINI_MODEL`\n",
    "- 源码\n",
    "    - gemini-cli prompts 设计\n",
    "        - https://github.com/google-gemini/gemini-cli/blob/main/packages/core/src/core/prompts.ts\n",
    "        - system prompt\n",
    "            - https://github.com/google-gemini/gemini-cli/blob/main/packages/core/src/core/prompts.ts#L40\n",
    "    - tokenLimit\n",
    "        - https://github.com/google-gemini/gemini-cli/blob/main/packages/core/src/core/tokenLimits.ts\n",
    "- sandbox 环境\n",
    "    - gemini -s\n",
    "        - gemini -s -p 'hello'"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6650406d-5a95-4adc-b548-3b845cc2eb40",
   "metadata": {},
   "source": [
    "- tasks\n",
    "    - `> 请翻译  <url> 的内容为中文，并保存为 Markdown 文件`"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c0d18eac-f4f5-45fc-8af8-4d780f6f5943",
   "metadata": {},
   "source": [
    "- `/tools`：自动配置\n",
    "    - Available Gemini CLI tools:\n",
    "        - shell\n",
    "        - google search\n",
    "- `/mcp`：手动配置"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7fffb134-d674-48a1-b718-b83b69fdcbb9",
   "metadata": {},
   "source": [
    "### 命令行参数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e4946504-7142-43af-bdbf-b1f3bfb1a83c",
   "metadata": {},
   "source": [
    "- `--model`\n",
    "- `--prompt`：直接回答问题，启用非交互模式\n",
    "- `--sandbox`\n",
    "- `--all_files`：递归包含当前目录中的所有文件作为上下文\n",
    "- `--yolo`：you only live once，自动 approve 所有工具调用"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ba08f041-f78b-4b8e-a7df-dca61bcc8301",
   "metadata": {},
   "source": [
    "### GEMINI.md"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ffad8945-1473-49a3-9d8a-10b85ad592a8",
   "metadata": {},
   "source": [
    "```\n",
    "1. 解释部分用中文，命令及代码用英文\n",
    "```\n",
    "- working directory\n",
    "- `~/.gemini/GEMINI.md`\n",
    "    - memory, user facts"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3357ab4b-c3ac-4934-99da-b490a342a626",
   "metadata": {},
   "source": [
    "### multi-modality"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a414aea7-41ba-4705-8c1c-fdf50f01ceaf",
   "metadata": {},
   "source": [
    "- 通过工具解析文件（jpg、pdf、mp3...）\n",
    "    - `ReadManyFiles`\n",
    "        - 文本 / SVG → 直接合并为字符串，插入到 prompt\n",
    "        - 图片 / PDF / 音视频 → 读取为 Base64，封装成\n",
    "```json\n",
    "{\n",
    "    inlineData: { mimeType: '<对应 MIME>', data: '<base64>' }\n",
    "}\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4e2031c5-e794-452a-b9d5-4082cd51dbbc",
   "metadata": {},
   "source": [
    "### 核心源码"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f1d26edc-4153-40d6-8833-1043b766a1cd",
   "metadata": {},
   "source": [
    "- config.ts\n",
    "    - registerCoreTool 各种 tool"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9910c48b-0ba2-46a6-b18a-05d4831e9caa",
   "metadata": {},
   "source": [
    "### memory tool"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "57b853fd-7c70-4a68-abed-14bfe536495c",
   "metadata": {},
   "source": [
    "```\n",
    "> remember that I'am 五道口纳什\n",
    "> Save Memory {\"fact\":\"My name is 五道口纳什\"}\n",
    "> 我是谁\n",
    "> 根据我记住的信息，你的名字是五道口纳什。\n",
    "```\n",
    "\n",
    "- https://github.com/google-gemini/gemini-cli/blob/main/packages/core/src/core/prompts.ts#L104\n",
    "- https://github.com/google-gemini/gemini-cli/blob/main/packages/core/src/tools/memoryTool.ts"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
